﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Project.Engine.Utilities;

namespace Project.Module.Common
{
    public class UrlSearching
    {
        public static string GetPageIdFromUrlSearch(string rawurl)
        {
            string detail = string.Empty;
            string[] arr = rawurl.Split(new string[] { "c=" }, StringSplitOptions.RemoveEmptyEntries);

            if (arr.Length >= 2) {
                string[] key = arr[1].Split(new string[] { "?" }, StringSplitOptions.RemoveEmptyEntries);
                if (key.Length > 0) {
                    detail = key[2];
                }
            }

            //return
            return detail;
        }

        public static string GetCateIdFromUrl(string rawurl)
        {
            string detail = string.Empty;
            string[] arr = rawurl.Split(new string[] { "c=" }, StringSplitOptions.RemoveEmptyEntries);

            if (arr.Length == 2)
            {
                string[] key = arr[1].Split(new string[] { "?key=" }, StringSplitOptions.RemoveEmptyEntries);
                if (key.Length == 2)
                {
                    detail = key[0];
                }
            }

            //return
            return detail;
        }

        public static string GetKeyFromUrl(string rawurl)
        {
            string detail = string.Empty;
            string[] arr = rawurl.Split(new string[] { "key=" }, StringSplitOptions.RemoveEmptyEntries);

            if (arr.Length > 0)
            {
                string[] key = arr[1].Split(new string[] { "?" }, StringSplitOptions.RemoveEmptyEntries);
                if (key.Length > 0)
                {
                    detail = key[0];
                }
            }

            //return
            return detail;
        }

        public static string GetKeyFromKeyword(string rawurl)
        {
            string result = rawurl;
            if (rawurl.Contains("?") == true)
            {
                int detail = rawurl.LastIndexOf("?");
                result = rawurl.Remove(detail);
            }

            // return
            return result;
        }

        public static int GetCateId(string choice)
        {
            int cateId = 0;
            if (choice == "1")
            {
                cateId = DefineUtil.nguyenLieuLamBanhId;
            }
            else if (choice == "2")
            {
                cateId = DefineUtil.nguyenLieuTrangTriId;
            }
            else if (choice == "3")
            {
                cateId = DefineUtil.dungCuLamBanhId;
            }
            else if (choice == "4")
            {
                cateId = DefineUtil.khuonId;
            }
            else if (choice == "5")
            {
                cateId = DefineUtil.doGiaDungId;
            }
            else if (choice == "6")
            {
                cateId = DefineUtil.sachId;
            }
            else if (choice == "7")
            {
                cateId = DefineUtil.congThucId;
            }

            return cateId;
        }
    }
}
